package pl.register.android.activities.correlation.builder;

import android.content.Context;
import android.widget.Button;
import pl.register.android.activities.correlation.logic.CorrelationStudentsPresenter;
import pl.register.android.classes.ClassesTopic;
import pl.register.android.lesson.LessonProgram;
import pl.register.android.util.StringUtils;

import java.util.Date;
import java.util.List;

/**
 * @author Mateusz Strzelecki
 * @since 2013-05-01
 */
public class ClassesDateEditorDialog extends DateDialogBuilder {

    private Button btnSchedule;

    private CorrelationStudentsPresenter presenter;


    private LessonProgram lessonProgram;

    public ClassesDateEditorDialog(Context context, LessonProgram lessonProgram, CorrelationStudentsPresenter presenter, Button btnSchedule) {
        super(context, lessonProgram.getClassesDate(), createDialogMsg(lessonProgram));
        this.lessonProgram = lessonProgram;
        this.presenter = presenter;
        this.btnSchedule = btnSchedule;
    }

    private static String createDialogMsg(LessonProgram lessonProgram) {
        List<ClassesTopic> classesTopics = lessonProgram.getClassesTopics();
        String msg = "Proszę wybrać nową datę zajęć: \n";
        for (int i = 0; i < classesTopics.size(); i++) {
            ClassesTopic classesTopic = classesTopics.get(i);
            if (i == 0) {
                msg += StringUtils.build("\'", classesTopic.getTopic(), "\'");
            } else {
                msg += StringUtils.build(" i ", "\'", classesTopic.getTopic(), "\'");
            }
        }
        return msg;
    }

    @Override
    protected void settleNewDate(Date newDate) {
        lessonProgram.setClassesDate(newDate);
        btnSchedule.setText(lessonProgram.getClassesDateInString());
        presenter.updateLessonProgram(lessonProgram);
    }
}
